<?php

namespace YmPhp\Admin\Http\Controllers\Business;

use YmPhp\Admin\Http\Repositories\Business\BusinessComment;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Models\Member\MemberList;
use YmPhp\Admin\Models\Business\BusinessList;
use YmPhp\Admin\Models\Business\BusinessCategory;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;

class BusinessCommentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BusinessComment(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('stid');
            $grid->column('type')->display(function ($value) {
                if ($value == 'business') {
                    $typeInfo = '商家' ;
                }else if ($value == 'mall') {
                    $typeInfo = '商品' ;
                }else{
                    $typeInfo = '其他' ;
                }
                return $typeInfo;
            });
            $grid->column('shid')->display(function ($value) {
                if ($this->type == 'business') {
                    $businessInfo = (new BusinessList())->getDetails($this->shid);
                    $business = $businessInfo->name . '<br>';
                    return $business;
                } else{
//                    $mallInfo = (new MallList())->getDetails($this->shid);
//                    $mall = $mallInfo->name . '<br>';
                    return '待定';
                }
            });
            $grid->column('cid')->display(function ($value) {
                if ($this->type == 'business') {
                    $categoryInfo = (new BusinessCategory())->getDetail($this->cid);
                    return $categoryInfo->name;
                }else{
                    return '待定';
                }
             });
            $grid->column('author')->display(function ($value) {
                $memberInfo = (new MemberList())->getDetails($this->authorid);
                $member = $memberInfo->username. '<br>';
                $member .= $memberInfo->mobile . '<br>';
                $member .= $memberInfo->realname ?? '未设置';

                return $member;
            });
            $grid->column('message')->width(300)->limit(50);
            $grid->column('star1')->display(function () {
                $configData = get_business_category_comment_id($this->cid,$this->star1,$this->star2,$this->star3);
                return $configData;
            });
            $grid->column('zans');
            $grid->column('views');
            $grid->column('shares');
            $grid->column('replies');
            $grid->column('jx')->switch();
            $grid->column('created_at')->sortable();
            $grid->disableViewButton();
            $grid->disableEditButton();
            $grid->disableCreateButton();
            $grid->showQuickEditButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id')->width(2);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new BusinessComment(), function (Show $show) {
            $show->field('id');
            $show->field('isnew');
            $show->field('type');
            $show->field('typeid');
            $show->field('shid');
            $show->field('hy_id');
            $show->field('authorid');
            $show->field('author');
            $show->field('niming');
            $show->field('subject');
            $show->field('message');
            $show->field('renjun');
            $show->field('xfh');
            $show->field('star1');
            $show->field('star2');
            $show->field('star3');
            $show->field('star4');
            $show->field('star5');
            $show->field('video');
            $show->field('video_cover');
            $show->field('tagid');
            $show->field('zans');
            $show->field('views');
            $show->field('shares');
            $show->field('replies');
            $show->field('jx');
            $show->field('lat');
            $show->field('lng');
            $show->field('album');
            $show->field('stid');
            $show->field('laizi');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BusinessComment(), function (Form $form) {
            $form->display('id');
            $form->text('isnew');
            $form->text('type');
            $form->text('typeid');
            $form->text('shid');
            $form->text('hy_id');
            $form->text('authorid');
            $form->text('author');
            $form->text('niming');
            $form->text('subject');
            $form->text('message');
            $form->text('renjun');
            $form->text('xfh');
            $form->text('star1');
            $form->text('star2');
            $form->text('star3');
            $form->text('star4');
            $form->text('star5');
            $form->text('video');
            $form->text('video_cover');
            $form->text('tagid');
            $form->text('zans');
            $form->text('views');
            $form->text('shares');
            $form->text('replies');
            $form->text('jx');
            $form->text('lat');
            $form->text('lng');
            $form->text('album');
            $form->text('stid');
            $form->text('laizi');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
